#pragma once
#include "Singleton.h"
#include <condition_variable>
#include <mutex>
#include <vector>
#include <thread>
#include <queue>
#include <functional>
#include <string>
#include <map>
class LogicNode;
class Session;

using FunCallBack = std::function<void(std::shared_ptr<Session> session,const short &msg_id,const std::string& msg_data)>;

class LogicSystem : public Singleton<LogicSystem>
{
    friend class Singleton<LogicSystem>;
public:
    ~LogicSystem();
    void PostMsgToQue(std::shared_ptr<LogicNode> logic_node);
    void stop();


private:
    LogicSystem(int thread_num=std::thread::hardware_concurrency());
    void DealMsg();
    void RegisterCallBack();


    void HelloWorldCallBack(std::shared_ptr<Session> session,const short &msg_id,const std::string& msg_data);
private:
    std::vector<std::thread> threads_;
    std::condition_variable cond_;
    std::mutex mutex_;
    bool b_stop_;
    std::queue<std::shared_ptr<LogicNode>> msg_que_;
    std::map<short,FunCallBack> fun_callbacks_;

};